﻿using System;
using System.Data;
using System.Text;

namespace ltModel.DAL
{
    /// <summary>
    /// 数据访问类article_content_only。
    /// </summary>
    public class article_content_only
    {
        public article_content_only()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int oid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from lt_article_content_only where oid=" + oid + "");
            return DataObject.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ltModel.Model.article_content_only model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into lt_article_content_only(");
            strSql.Append("title,content,classtype,addtime");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.title + "',");
            strSql.Append("'" + model.content + "',");
            strSql.Append("'" + model.classtype + "',");
            strSql.Append("'" + model.addtime + "'");
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DataObject.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ltModel.Model.article_content_only model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_article_content_only set ");
            if (model.title != null)
                strSql.Append("title='" + model.title + "',");
            if (model.content != null)
                strSql.Append("content='" + model.content + "',");
            if (model.classtype != null)
                strSql.Append("classtype='" + model.classtype + "',");
            strSql.Append(" addtime=addtime ");
            strSql.Append(" where oid=" + model.oid + "");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int oid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_article_content_only ");
            strSql.Append(" where oid=" + oid);
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ltModel.Model.article_content_only GetModel(int oid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append(" [oid],[title],[content],[classtype],[addtime] ");
            strSql.Append(" from lt_article_content_only ");
            strSql.Append(" where oid=" + oid);
            ltModel.Model.article_content_only model = new ltModel.Model.article_content_only();
            DataSet ds = DataObject.Query(strSql.ToString());
            model.oid = oid;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.title = ds.Tables[0].Rows[0]["title"].ToString();
                model.content = ds.Tables[0].Rows[0]["content"].ToString();
                model.classtype = ds.Tables[0].Rows[0]["classtype"].ToString();
                model.addtime = ds.Tables[0].Rows[0]["addtime"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [oid],[title],[content],[classtype],[addtime] ");
            strSql.Append(" FROM lt_article_content_only ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DataObject.Query(strSql.ToString());
        }

        #endregion  成员方法
    }
}